package com.jie.server.modules.platform.conreoller;

import com.jie.common.annotation.Log;
import com.jie.common.controller.BaseController;
import com.jie.common.enums.BusinessType;
import com.jie.common.page.TableDataInfo;
import com.jie.common.result.R;
import com.jie.server.modules.platform.entity.TenantPackage;
import com.jie.server.modules.platform.service.ITenantPackageService;
import com.jie.server.modules.platform.vo.SimplePackage;
import com.jie.server.utils.ExcelUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @description: 租户套餐 前端控制层
 * @author: xiaojie
 * @since: 2024/12/17 0017
 */
@Api(tags = "租户套餐管理")
@RestController
@RequestMapping("/platform/package")
public class TenantPackageController extends BaseController {

    @Autowired
    private ITenantPackageService tenantPackageService;

    /**
     * 查询租户套餐表列表
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:list')")
    @GetMapping("/list")
    public TableDataInfo list(TenantPackage tenantPackage) {
        startPage();
        List<TenantPackage> list = tenantPackageService.selectTenantPackageList(tenantPackage);
        return getDataTable(list);
    }

    /**
     * 导出租户套餐表列表
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:export')")
    @Log(title = "租户套餐表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantPackage tenantPackage) {
        List<TenantPackage> list = tenantPackageService.selectTenantPackageList(tenantPackage);
        ExcelUtils.exportEasyExcel(response,TenantPackage.class,list,"租户套餐表数据");
    }

    /**
     * 获取租户套餐表详细信息
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:query')")
    @GetMapping(value = "/{packageId}")
    public R getInfo(@PathVariable("packageId") Long packageId) {
        return R.ok(tenantPackageService.selectTenantPackageByPackageId(packageId));
    }

    /**
     * 新增租户套餐表
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:create')")
    @Log(title = "租户套餐表", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody TenantPackage tenantPackage) {
        boolean success = tenantPackageService.create(tenantPackage);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改租户套餐表
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:edit')")
    @Log(title = "租户套餐表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{packageId}")
    public R update(@PathVariable Long packageId,  @RequestBody TenantPackage tenantPackage) {
        tenantPackage.setPackageId(packageId);
        boolean success = tenantPackageService.update(tenantPackage);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除租户套餐表
     */
    @PreAuthorize("@customSs.hasPermi('platform:package:remove')")
    @Log(title = "租户套餐表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{packageIds}")
    public R remove(@PathVariable Long[] packageIds) {
        return R.ok(tenantPackageService.deleteTenantPackageByPackageIds(packageIds));
    }

    /**
     * 查询租户套餐精简列表
     */
    @GetMapping("/get-simple-list")
    public R getSimpleList() {
        List<SimplePackage> list = tenantPackageService.getSimpleList();
        return  R.ok(list);
    }

}
